<link href="__PUBLIC__/css/style.default.css" rel="stylesheet">

<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="__PUBLIC__/js/html5shiv.js"></script>
<script src="__PUBLIC__/js/respond.min.js"></script>
<![endif]-->
<style>
    .param_div .form-control{
        padding: 5px;
    }

    .param_div .param_lable{
        padding-top: 5px;
        padding-left: 0px;
    }

</style>
<div class="mainpanel">
    <div class="pageheader">
        <div class="media">
            <div class="pageicon pull-left">
                <i class="fa fa-th-list"></i>
            </div>
            <div class="media-body">
                <ul class="breadcrumb">
                    <li><a href=""><i class="glyphicon glyphicon-home"></i></a></li>
                    <li><a href="">首页</a></li>
                    <li>版本管理</li>
                </ul>
                <h4>版本管理</h4>
            </div>
        </div><!-- media -->
    </div>

    <div class="contentpanel">

        <div class="panel panel-primary-head">
            <div id="succ_file_s" class="alert alert-success hides">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <strong>版本添加成功</strong>
            </div>

            <div id="faild_file_s" class="alert alert-danger hides">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <strong>版本添加失败,请检查！</strong>
            </div>

            <div class="row" style="padding: 0 15px">


            </div>

            <div class="row">
                <div class="col-md-6">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <div class="panel-btns" style="display: none;">
                                <a href="" class="panel-minimize tooltips maximize" data-toggle="tooltip" title="" data-original-title="Minimize Panel">
                                    <i class="fa fa-plus"></i>
                                </a>
                            </div><!-- panel-btns -->
                            <h4 class="panel-title">添加版本</h4>
                            <p style="    color: #fff;">点击右上角显示更多</p>
                        </div><!-- panel-heading -->
                        <div class="panel-body" style="display: none;">
                            <form id="user_add_ajaxForm" method="post" action="{:url('admin/devicesoftware/add')}" enctype="multipart/form-data">
                                
                                <div class="row">
                                    <div class="form-group col-md-4">
                                        <label>版本名</label>
                                        <input type="text" name="name" placeholder="版本名" class="form-control">
                                    </div>

                                    <div class="form-group col-md-4" >
                                        <label>类型</label>
                                        <input  name="dev_type" placeholder="类型" class="form-control">
                                    </div>
                                    <div class="form-group col-md-4" >
                                        <label>软件版本</label>
                                        <input  name="dev_edition" placeholder="软件版本" class="form-control">
                                    </div>

                                </div>
                                <div class="row">
                                    <div class="form-group col-md-12" >
                                        <label>描述</label>
                                    <textarea name="desc" class="form-control"></textarea>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="form-group col-md-4" >
                                        <label>选择文件</label>
                                        <input id="dev_soft_file_add" type="file" name="filecontent" class="hides" style="display: none">
                                        <button type="button"  name="dev_edition" placeholder="选择文件"
                                                onclick="$('#dev_soft_file_add').click()"
                                                class="btn btn-primary form-control">选择文件</button>
                                    </div>

                                </div><!-- row -->
                            </form>

                        </div><!-- panel-body -->

                        <div class="panel-footer" style="display: none;">
                            <button id="USER_ADD_FROM_BTN" class="btn btn-primary">添加</button>
                        </div><!-- panel-footer -->
                    </div><!-- panel -->

                </div>
            </div>
            <!--查询条件-->
            <div class="row param_div hides">
                <div class="col-md-3">
                    <div class="col-md-4 param_lable">
                        <label>创建开始时间：</label>
                    </div>
                    <div class="col-md-8 param_input">
                        <input name="begin_createtime"  class="form-control">
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="col-md-4 param_lable">
                        <label>创建结束时间：</label>
                    </div>
                    <div class="col-md-8 param_input">
                        <input name="end_createtime"  class="form-control">
                    </div>
                </div>
                <div class="col-md-3">
                    <button class="btn btn-primary btn-sm">查询</button>
                </div>
            </div>

            <table id="exRowTable" class="table table-striped table-bordered">
                <thead>
                <tr>
                    <th>序号</th>
                    <th>版本名</th>
                    <th>版本</th>
                    <th>创建时间</th>
                    <th>类型</th>
                    <th>文件名</th>
                    <th>描述</th>
                    <th>操作</th>
                </tr>
                </thead>
            </table>
        </div><!-- panel -->

    </div>

</div>
<!--madol 修改密码 hide-->
<div id="user_paw_save_madol" class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">&times;</button>
                <h4 class="modal-title"><span id="username_save"></span>修改密码</h4>
            </div>
            <div class="modal-body">
                <div id="user_paw_save_param" class="row" style="padding-right: 2rem;padding-left: 2rem">
                    <div class="row">
                        <label>原密码</label>
                        <input type="password" name="ipwd"  class="form-control">
                        <input id="username_param" type="hidden" name="username_param">
                    </div>
                    <div class="row">
                        <label>新密码</label>
                        <input type="password" name="npwd"  class="form-control">
                    </div>
                    <div class="row">
                        <label>重复新密码</label>
                        <input type="password" name="renpwd"  class="form-control">
                    </div>
                    <div class="row" style="padding-right: 1rem;padding-top: 1rem" >
                        <button style="float: right;" id="USER_PWD_EDIT_FROM_BTN" class="btn btn-primary">提交</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<style>
    .hides{
        display: none;
    }

</style>
<script>
    jQuery('#select-search-hide').select2({
        minimumResultsForSearch: -1
    });
    var exRowTable;
    $(function(){

        var role_mark = {$Think.session.user.user_role};

        $('#user_add_ajaxForm [name="user_role"]').val(role_mark+1)

        $("#USER_MADOL_ADD_BTN").click(function () {
            $("#user_add_madol").modal("show")
        })
        // 添加版本
        $("#USER_ADD_FROM_BTN").click(function () {

            var user_name = $("#user_add_ajaxForm").find('[name = "name"]').val()
            var user_paw = $("#user_add_ajaxForm").find('[name = "acc_pwd"]').val()
            var re_acc_pwd = $("#user_add_ajaxForm").find('[name = "re_acc_pwd"]').val()
            // 账号
            if(user_name == null || user_name == undefined || user_name == ''){
                $("#user_add_ajaxForm").find('[name = "acc_name"]').focus()
                alert("版本名不能为空")
                return;
            }
            // return;
            $("#user_add_ajaxForm").ajaxSubmit(function (data) {
                console.log(data)
                if(data == 1){
                    $(".hides").hide()
                    $("#faild_file_s").html('版本添加失败')
                    $("#faild_file_s").show()
                }else{
                    $(".hides").hide()
                    $("#succ_file_s").html('版本添加成功')
                    $("#succ_file_s").show()
                }
                exRowTable.ajax.reload();
            });


        })
        // 修改版本
        $("#USER_PWD_EDIT_FROM_BTN").click(function () {
            var ipwd = $("#user_paw_save_param").find('[name = "ipwd"]').val()
            var npwd = $("#user_paw_save_param").find('[name = "npwd"]').val()
            var renpwd = $("#user_paw_save_param").find('[name = "renpwd"]').val()
            var acc_name = $("#user_paw_save_param").find('[name = "username_param"]').val()

            if(npwd == renpwd){
                $.post("{:url('admin/user/userupd')}",{acc_pwd:npwd,acc_name:acc_name},function (data) {
                    if(data == 1){
                        alert('修改成功')
                    }else{
                        alert("修改失败")
                    }
                })
            }else{
                alert("新密码两次不一致！请检查")
            }
        })

        $("[data-toggle='tooltip']").tooltip();




        exRowTable = $('#exRowTable').DataTable({
            responsive: true,
            "fnDrawCallback": function(oSettings) {
                jQuery('#exRowTable_paginate ul').addClass('pagination-active-success');
            },
            "ajax": "{:url('admin/devicesoftware/query')}",
            "columns": [
                { "data": "id" },
                { "data": "name" },
                { "data": "dev_edition" },
                { "data": "create_time" },
                { "data": "dev_type" },
                { "data": "file_name" },
                { "data": "desc" },
                { "data": "id","render": function ( data, type, full, meta ) {
                        return '<button onclick="user_del('+data+')" class="btn btn-danger btn-xs">删除</button>';
                    }},
            ],
            "order": [[0, 'desc']]
        });




    })
    // 删除版本
    function user_del(id) {
        if(confirm('确认删除！')){
            $.post("{:url('admin/devicesoftware/del')}",{ID:id},function (data) {
                if(data == 1){
                    exRowTable.ajax.reload();
                    alert('删除成功')
                    // console.log('删除成功')
                }else{
                    alert("该版本不能删除")
                }
                exRowTable.ajax.reload();
            })
        }
    }

    function user_paw_save_view(id,acc_name) {
        $("#username_save").html(acc_name)
        $("#username_param").val(acc_name)
        $("#user_paw_save_madol").modal('show')
    }


</script>



